//
//  CKAccountModel.m
//  FreshBee
//
//  Created by chenkai on 16/10/15.
//  Copyright © 2016年 iOS013. All rights reserved.
//

#import "CKOrderModel.h"
#import "NetWorkTool.h"
#import "CKOrderGoods.h"
#import "CKStatusTimeline.h"

@implementation CKOrderModel

- (void)setOrder_goods:(NSArray *)order_goods{

    NSMutableArray *nmArray = [NSMutableArray array];
    for (NSArray *array in order_goods) {
        CKOrderGoods *goods = [[CKOrderGoods alloc]init];
        [goods setValuesForKeysWithDictionary:array[0]];
        [nmArray addObject:goods];
    }
    _order_goods = nmArray;
}
- (void)setStatus_timeline:(NSArray<CKStatusTimeline *> *)status_timeline{
    NSMutableArray *nmArray = [NSMutableArray array];
    for (NSDictionary *dict in status_timeline) {
        CKStatusTimeline *goods = [[CKStatusTimeline alloc]init];
        [goods setValuesForKeysWithDictionary:dict];
        [nmArray addObject:goods];
    }
    _status_timeline = nmArray;
}

+ (instancetype)sharedOrder{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
    });
    return instance;
}



+ (void)getDataWithsuccessBlock:(void(^)(NSArray *array))successBlock{
    [[NetWorkTool shareManager]POST_RequestWithUrlString:@"http://iosapi.itcast.cn/loveBeen/MyOrders.json.php" parmas:@{@"call":@13} successBloock:^(id responseObject) {

        NSDictionary *dict = responseObject;
        NSArray *dataArray = dict[@"data"];
        NSMutableArray *nmArray = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            CKOrderModel *orderModel = [[CKOrderModel alloc]init];
            [orderModel setValuesForKeysWithDictionary:dict];
            [nmArray addObject:orderModel];
        }
        successBlock(nmArray.copy);
        [CKOrderModel sharedOrder].orderModelArray = nmArray.copy;
        
        
    } failureBlock:^(NSError *error) {
        NSLog(@"获取数据失败");
    }];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}

@end
